﻿using System;
using Enums;
using XF.ExControls;
using XF.Common;
using System.Windows.Forms;

namespace KYBM
{
    public partial class FrmDialogReceipt : XFFormEx
    {
        readonly XF.BLL.Base_Customer bllCustomer = new XF.BLL.Base_Customer();
        public XF.Model.Bill_Receipt Receipt { get; set; } = new XF.Model.Bill_Receipt();

        public FrmDialogReceipt()
        {
            InitializeComponent();
        }

        private void tsBtnSure_Click(object sender, EventArgs e)
        {
            decimal paidAmount;
            if(!decimal.TryParse(tbReceipt.Text,out paidAmount))
            {
                QQMessageBox.Show(
                            this,
                            MessageText.CHECK_ERROR_PAID,
                            MessageText.MESSAGEBOX_CAPTION_TIP,
                            QQMessageBoxIcon.Information,
                            QQMessageBoxButtons.OK);
                return;
            }
            Receipt.PaidDate = dtpReceiptDate.Value;
            Receipt.PaidItem = tbPaidItem.Text;
            Receipt.PaidAmount = paidAmount;
            Receipt.Remark = tbRemark.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void FrmDialogCheckOut_Load(object sender, EventArgs e)
        {
            tbCode.Text = Receipt.CustomerCode;
            tbName.Text = Receipt.CustomerName;
            dtpReceiptDate.Value = Receipt.PaidDate;
            tbReceipt.Text = Receipt.PaidAmount.ToString("0.######");
            tbPaidItem.Text = Receipt.PaidItem;
            tbRemark.Text = Receipt.Remark;
        }

        private void tsBtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmDialogReceipt_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    tsBtnSure_Click(this, EventArgs.Empty);
                    break;
                case Keys.Escape:
                    tsBtnCancel_Click(this, EventArgs.Empty);
                    break;
            }
        }
    }
}
